package org.example.lys.utils;

import java.util.Random;
import java.util.UUID;

/**
 * @author wuxiaobo
 * @date 2019/7/29 12:58
 */
public class RandomUtils {
    private static Random random = new Random();

    /**
     * 返回手机号码
     */
    private static String[] telFirst="134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153".split(",");

    /**
     * 生成随机字母(小写)
     *
     * @return
     */
    public static char getRandomChar() {
        return (char) (random.nextInt(26) + 'a');
    }

    /**
     * 生成随机数字
     *
     * @return
     */
    public static char getRandomNum() {
        return (char) (random.nextInt(10) + '0');
    }

    /**
     * 生成指定数量的字母字符串(小写)
     *
     * @param count
     * @return
     */
    public static String getRandomChar(int count) {
        StringBuilder rs = new StringBuilder();
        while (count-- > 0) {

            rs.append(getRandomChar());
        }
        return rs.toString();
    }

    /**
     * 生成指定数量的随数字
     *
     * @param count
     * @return
     */
    public static String getRandomNumber(int count) {
        StringBuilder rs = new StringBuilder();
        while (count-- > 0) {

            rs.append(getRandomNum());
        }
        return rs.toString();
    }

    /**
     * 获取uuid
     *
     * @return
     */
    public static String getUUID() {
        return UUID.randomUUID().toString();
    }

    public static String getValidateCode() {
        String numbel = Math.random() * 10000 + "";
        String num = numbel.substring(0, 4);
        return num;
    }


    /**
     * 随机生成手机号
     * @return
     */
    public static String genPhoneNum() {
        int index = getNum(0,telFirst.length-1);
        String first= telFirst[index];
        String second = String.valueOf(getNum(1,888)+10000).substring(1);
        String third = String.valueOf(getNum(1,9100)+10000).substring(1);
        return first + second+third;
    }

    /**
     * 获取随机数
     * @param start
     * @param end
     * @return
     */
    private static int getNum(int start,int end) {
        return (int)(Math.random()*(end-start+1)+start);
    }
}
